﻿using NPinyin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KWT.DRG_DIP.Common
{
    public static class _Tool
    {
        public static string ToPinYin(string str)
        {
            string temp = "";
            if (string.IsNullOrEmpty(str))
                return temp;
            foreach (var item in str.ToCharArray())
            {
                var a = Pinyin.GetPinyin(item).ToArray().FirstOrDefault().ToString();
                temp += a;
            }
            return temp;
        }
        public static string CreateRandomNumber()
        {
            Random ran = new Random();
            int number = ran.Next(0, 9999);
            string num;
            if (number < 1000)
            {
                num = number.ToString("0000");
            }
            else
            {
                num = number.ToString();
            }
            return num;
        }

        public static string RandomString(int length)
        {
            var random = new Random();
            var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            return new string(Enumerable.Repeat(chars, length)
                .Select(x => x[random.Next(x.Length)]).ToArray());
        }
    }
}
